package cn.gok;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

class Book1{
    private int bid;
    private String name;
    private float price;

    public Book1(int bid, String name, float price) {
        this.bid = bid;
        this.name = name;
        this.price = price;
    }

    @Override
    public String toString() {
        return "Book1{" +
                "bid=" + bid +
                ", name='" + name + '\'' +
                ", price=" + price +
                '}';
    }

    public int getBid() {
        return bid;
    }

    public void setBid(int bid) {
        this.bid = bid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public float getPrice() {
        return price;
    }

    public void setPrice(float price) {
        this.price = price;
    }
    public void sell1(){
        System.out.println("这本书被卖掉了");
    }
    public void sell2(float price,String person){
        System.out.println("本书卖给了"+person+"卖了"+price+"元");
    }
}
public class homework7 {
    public static void main(String[] args) throws NoSuchMethodException, ClassNotFoundException, InvocationTargetException, InstantiationException, IllegalAccessException,NoSuchFieldException {
        作业();
    }


    private static void 作业() throws NoSuchMethodException, ClassNotFoundException, InvocationTargetException, InstantiationException, IllegalAccessException {
       //1
        Class c=Class.forName("cn.gok.Book1");
        for(Constructor con:c.getDeclaredConstructors()){
            System.out.println(con);
        }
        //2
        Constructor con=c.getConstructor(int.class,String.class,float.class);
        Book1 book1=(Book1) con.newInstance(1,"西游记",20.0f);
        System.out.println(book1);
        //3
        Method m = c.getDeclaredMethod("sell1",null);
        m.setAccessible(true);
        m.invoke(book1,null);
        Method m1 = c.getDeclaredMethod("sell2",float.class,String.class);
        m1.setAccessible(true);
        m1.invoke(book1,90.0f,"老白");
    }
}
